<?php
/**
 * 社团 会员列表
 */
namespace backend\controllers;

use bc\controller\BackendController;
use backend\models\organization\OrganizationModel;
use backend\models\organization\UserModel;
use bc\util\backend\Page;

class OrganizationUserController extends BackendController
{
	
	/**
	 * 社团活动统一需带的社团id
	 * @var int
	 */
	private $organizationId;
	
	public function beforeAction($action)
	{
		$organizationId = $this->get('organization_id');
		if(!$organizationId)
			$this->redirect('/');
		
		$this->organizationId = $organizationId;
		return parent::beforeAction($action);
	}
	
	
	/**
	 * 列表页
	 */
	public function actionIndex()
	{
		$model = new UserModel();
		$OrganizationModel = new OrganizationModel();
		$params = 'organization_id = '.$this->organizationId;
		
		$page = $this->get('page', 1);
		$model->sort = 'organization_user_id';
		$list = $model->getUserList($params, $page, self::PAGE_SIZE);
		
		$total = $model->getUserTotal($params);
		
		$pagination = new Page($total, self::PAGE_SIZE);
		
		$view['list'] = $list;
		$view['pagination'] = $pagination;
		
		$view['organization_id'] = $this->organizationId;
		$view['organization'] = $OrganizationModel->getRowById($this->organizationId);
		
		return $this->render('index', $view);
	}
	
	/**
	 * 编辑
	 */
	public function actionEdit()
	{
		$id = $this->get('id');
		if(!$id)
			$this->redirect('/');
		
		$model = new UserModel();
		$row = $model->getRowById($id);
		
		if(!$row)
			$this->redirect('/');
		
		$view['row'] = $row;
		$view['organization_id'] = $this->organizationId;
		
		return $this->render('edit', $view);
	}
	
}

